package com.api.shopapi.mapper;

import com.api.shopapi.entity.ElderlyCheckinAssess;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ElderlyCheckinAssessMapper {

    @Insert("insert into elderly_checkin_assess " +
            "(ElderlyCheckinAssessCode," +
            "ElderlyCode," +
            "ElderlyName," +
            "Fraction," +
            "CreateTime," +
            "StaffCode," +
            "InstitutionCode," +
            "MedicinerCode," +
            "MedicinerName," +
            "NurseCode," +
            "NurseName," +
            "RecordType," +
            "CheckinAssessLevel" +
            ")value(" +
            "#{elderlyCheckinAssess.ElderlyCheckinAssessCode}," +
            "#{elderlyCheckinAssess.ElderlyCode}," +
            "#{elderlyCheckinAssess.ElderlyName}," +
            "#{elderlyCheckinAssess.Fraction}," +
            "#{elderlyCheckinAssess.CreateTime}," +
            "#{elderlyCheckinAssess.StaffCode}," +
            "#{elderlyCheckinAssess.InstitutionCode}," +
            "#{elderlyCheckinAssess.MedicinerCode}," +
            "#{elderlyCheckinAssess.MedicinerName}," +
            "#{elderlyCheckinAssess.NurseCode}," +
            "#{elderlyCheckinAssess.NurseName}," +
            "#{elderlyCheckinAssess.RecordType}," +
            "#{elderlyCheckinAssess.CheckinAssessLevel})")
    int insert(@Param("elderlyCheckinAssess") ElderlyCheckinAssess elderlyCheckinAssess);

    @Delete("delete from elderly_checkin_assess where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode}")
    int deleteByElderlyCheckinAssessCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode);

    @Update("update elderly_checkin_assess" +
            " set" +
            "Fraction=#{elderlyCheckinAssess.Fraction}," +
            "CheckinAssessLevel=#{elderlyCheckinAssess.CheckinAssessLevel} " +
            " where ElderlyCheckinAssessCode=#{elderlyCheckinAssess.ElderlyCheckinAssessCode}")
    int updateByElderlyCheckinAssessCode(@Param("elderlyCheckinAssess") ElderlyCheckinAssess elderlyCheckinAssess);


    @Select("select * from elderly_checkin_assess where ElderlyCheckinAssessCode=#{elderlyCheckinAssessCode} limit 1")
    ElderlyCheckinAssess getByElderlyCheckinAssessCode(@Param("elderlyCheckinAssessCode") String elderlyCheckinAssessCode);

    @Select("select * from elderly_checkin_assess where ElderlyCode=#{elderlyCode} limit 1")
    ElderlyCheckinAssess getByElderlyCode(@Param("elderlyCode") String elderlyCode);

    @Select("select * from elderly_checkin_assess where InstitutionCode=#{institutionCode} order by CreateTime DESC")
    List<ElderlyCheckinAssess> getListByInstitutionCode(@Param("institutionCode") String institutionCode);


    @Select("<script>" +
            "select * from elderly_checkin_assess " +
            "where InstitutionCode=#{institutionCode} " +
            "<if test ='elderlyName !=null and elderlyName!=\"\" '>" +
            "and ElderlyName like concat('%',#{elderlyName},'%') " +
            "</if>" +
            "order by CreateTime DESC" +
            "</script>")
    List<ElderlyCheckinAssess> getPageList(@Param("institutionCode") String institutionCode,@Param("elderlyName") String elderlyName);

    @Select("<script>" +
            "select * from elderly_checkin_assess " +
            " where InstitutionCode in (select institutionCode from institution where governmentCode=#{governmentCode}) " +
            "<if test ='elderlyName !=null and elderlyName!=\"\" '>" +
            " and ElderlyName like concat('%',#{elderlyName},'%') " +
            "</if>" +
            " order by CreateTime DESC" +
            "</script>")
    List<ElderlyCheckinAssess> pageByGovCode(@Param("governmentCode") String governmentCode,@Param("elderlyName") String elderlyName);


    @Select("<script>" +
            "select * from elderly_checkin_assess " +
            " where elderlyCode =#{elderlyCode} " +
            " order by CreateTime DESC" +
            "</script>")
    List<ElderlyCheckinAssess> listByElderlyCode(@Param("elderlyCode") String elderlyCode);


    @Select("<script>" +
            "select * from elderly_checkin_assess " +
            " where medicinerCode =#{medicinerCode} " +
            " order by CreateTime DESC" +
            "</script>")
    List<ElderlyCheckinAssess> listByMedicinerCode(@Param("medicinerCode") String medicinerCode);


    @Select("<script>" +
            "select * from elderly_checkin_assess " +
            " where nurseCode =#{nurseCode} " +
            " order by CreateTime DESC" +
            "</script>")
    List<ElderlyCheckinAssess> listByNurseCode(@Param("nurseCode") String nurseCode);




}
